//
// Created by Win10 on 2022/10/31.
//

#include<iostream>
#include "sh_stack.h"

using namespace std;

bool StackEmpty(ShStack S) {
    if (S.top0 == -1 && S.top1 == MaxSize) {
        return true;
    }
    return false;
}

bool StackFull(ShStack S) {
    if (S.top0 + 1 == S.top1) return true;
    return false;
}

bool Push0(ShStack& S, ElemType x) {
    if (StackFull(S) ){
        return false;
    }
    S.data[++S.top0] = x;
    return true;
}

bool Push1(ShStack& S, ElemType x) {
    if (StackFull(S) ){
        return false;
    }
    S.data[--S.top1] = x;
    return true;
}

bool Pop0(ShStack& S, ElemType& x) {
    if (S.top0 == -1) return false;
    x = S.data[S.top0--];
    return true;
}

bool Pop1(ShStack& S, ElemType& x) {
    if (S.top1 == MaxSize) return false;
    x = S.data[S.top1++];
    return true;
}

bool GetTop0(ShStack S, ElemType& x) {
    if (S.top0 == -1) return false;
    x = S.data[S.top0];
    return true;
}

bool GetTop1(ShStack S, ElemType& x) {
    if (S.top1 == MaxSize) return false;
    x = S.data[S.top1];
    return true;
}

int main() {
    {
        ShStack S;
        InitStack(S);
        for (int i = 1; i <= 5; i++) {
            Push0(S, i);
        }
        for (int i = 1; i <= 5; i++) {
            Push1(S, i);
        }
        ElemType x;
        GetTop0(S, x);
        cout << x << endl;

        GetTop1(S, x);
        cout << x << endl;

        bool f = Push0(S, 6);
        if (f) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }

        f = Push1(S, 6);
        if (f) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }

        while (Pop0(S,x)) {
            cout << x << endl;
        }
        while (Pop1(S, x)) {
            cout << x << endl;
        }
    }
    return 0;
}